// Copyright 2009 StarCite Inc.  All rights reserved.
// ProductFactory.java 3:11:51 PM danny.liu
package com.billowsoft.sample.thread.lock;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author danny.liu Apr 18, 2012
 * @version 1.0
 * 
 */
public class ProductFactory {

	private Queue<Product> products;
	
	private Lock lock;
	
	public ProductFactory(){
		this.products = new LinkedBlockingDeque<Product>();
		this.lock = new ReentrantLock();
	}
	
	public void lock(){
		lock.lock();
	}
	
	public void unlock(){
		lock.unlock();
	}
	
	public Boolean hasProduct(){
		return !products.isEmpty();
	}
	
	public Product getProduct(){
		return products.poll();
	}
	
	public void createProduct(Product product){
		products.add(product);
	}
}
